﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using IMS_Data;

namespace IMS_WEB
{
    /// <summary>
    /// Summary description for WebService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class WebService : System.Web.Services.WebService
    {
        public WebService()
        {
        
        }
        
        [WebMethod]
        public string[] GetProductList(string prefixText, int count)
        {
            string sql = string.Format("select * from product where product_name like '%{0}%'", prefixText);
            ProductReposity cr = new ProductReposity();

            var products = cr.QueryProduct(sql);
            List<string> names = new List<string>();
            foreach (var ele in products)
            {
                names.Add(ele.product_name.Trim());
            }

            return names.ToArray();
            //return new string[] { "aa", "bb", "cc" };

        }
        [WebMethod]
        public string[] GetCompanyList(string prefixText, int count)
        {
            string sql = string.Format("select * from company where company_name like '%{0}%'", prefixText);
            CompanyReposity cr = new CompanyReposity();

            var companys = cr.QueryCompany(sql);
            List<string> names = new List<string>();
            foreach (var ele in companys)
            {
                names.Add(ele.company_name.Trim());
            }

            return names.ToArray();
            //return new string[] { "aa", "bb", "cc" };

        }
    }
}
